package company.C58_AC;

import java.util.*;

public class C1 {

    public ArrayList<String> findCommonString(ArrayList<ArrayList<String>> values) {
        Map<String, Integer> dict = new LinkedHashMap<>();
        for (ArrayList<String> list : values) {
            Set<String> set = new HashSet<>();
            for (String str : list) {
                if (set.contains(str))
                    continue;
                dict.put(str, dict.getOrDefault(str, 0) + 1);
                set.add(str);
            }
        }
        int size = values.size();
        ArrayList<String> result = new ArrayList<>();
        for (Map.Entry<String, Integer> e : dict.entrySet()) {
            if (e.getValue() == size)
                result.add(e.getKey());
        }
        return result;
    }
}
